import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'

// Import Element Plus
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import './assets/styles/dark.css'
// Set up VSCode API
declare global {
  interface Window {
    vscode: { postMessage: (message: any) => void; };
    initialRoute: string;
  }
}

const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
// Register Element Plus
app.use(ElementPlus);
// 首先配置路由
app.use(router);

// 然后再导航到初始路由（如果提供了的话）
if (window.initialRoute) {
  console.log('Navigating to initial route:', window.initialRoute);
  
  // 移除哈希符号如果存在，因为router.push不需要它
  const route = window.initialRoute.startsWith('#') 
    ? window.initialRoute.substring(1) 
    : window.initialRoute;
    
  router.push(route).catch(err => {
    console.error('Failed to navigate to initial route:', err);
  });
}

// 最后挂载应用
app.mount('#app');
